home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_hdr_light.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  2.5 KB  |  104 lines

  1. /*Environment Light to project an environment map onto 3D geometry - designed
  2. * to work with 32 bit floating point TIFF environment maps to give a higher
  3. * dynamic range and more realistic colours.
  4. *  
  5. *Created by Simon Bunker 27th September 2001
  6. *simon@rendermania.com http://www.rendermania.com/HDRI/
  7. *
  8. *This shader is made freely available under the proviso that this copyright
  9. *notice remain intact and that I am acknowledged as the original author. Please
  10. *post links back to the above address*or get in contact if you have any queries
  11. *or bug reports related to this shader 
  12. *
  13. */
  14.  
  15.  
  16. color hdrenv(string envname;vector R;float blur)
  17. {
  18.     color hdrtex;
  19.  
  20.     vector D = normalize(vtransform("world",R));
  21.  
  22.     float Dx = xcomp(D);
  23.     float Dy = ycomp(D);
  24.     float Dz = zcomp(D);
  25.  
  26.     float r = 0.159154943 * acos(Dz) / sqrt((Dx * Dx) + (Dy * Dy));
  27.  
  28.     float ss = 0.5 + (Dx * r);
  29.     float tt = 0.5 + (Dy * r);
  30.     ss = 1 - ss;
  31.  
  32.     if(envname !="") {
  33.         hdrtex = texture(envname,ss,tt,"blur",blur);
  34.     }
  35.  
  36.     return hdrtex;
  37. }
  38.  
  39.  
  40. light k3d_hdr_light (
  41.     float intensity =1.0;
  42.     float exposure_compensation_stops = 0.0;
  43.     string envname = "";
  44.     string envspace = "shader";
  45.     string mappingtype = "probe";
  46.     point origin = (0,0,0);
  47.     float blur = 0.0;
  48.     float shadowmapping = 0.0;
  49.     string shadowname = "";
  50.     float shadowsamples = 16.0;
  51.     float shadowblur = 0.0;
  52.     float shadowbias = 0.0;
  53.     )
  54. {
  55.  
  56. /* Code based off of Larry Gritz's Uberlight Shader */
  57. #ifdef BMRT
  58. vector axis = normalize(N);
  59. #else
  60. vector axis = normalize(vector "shader" (0,0,1));
  61. #endif
  62.  
  63.     solar (-axis, 1.570796327) {
  64.         color Ct;
  65.  
  66.         /*Use light ray direction as map lookup NB L points from surface to lightsource*/
  67.         vector R = normalize(vtransform(envspace,L));
  68.  
  69.         /*Else bright red colour warns if light is not picking up texture*/
  70.         if (mappingtype == ""){
  71.             Ct = color (1,0,0);
  72.             printf("Please select mapping type probe,environment or planar");
  73.         }
  74.  
  75.         if (mappingtype == "probe"){
  76.             if(envname != ""){
  77.                 Ct = hdrenv(envname,R,blur);
  78.             }
  79.         }
  80.         else if (mappingtype == "environment"){
  81.             if(envname != ""){
  82.                 Ct = environment(envname,R,"blur",blur);
  83.             }
  84.         }
  85.         else if (mappingtype == "planar"){
  86.             if(envname != ""){
  87.                 Ct = texture(envname,s,t,"blur",blur);
  88.             }
  89.         }
  90.  
  91.         float exposure = pow(2,exposure_compensation_stops);
  92.  
  93.         if (shadowmapping == 1){
  94.                 if (shadowname != "") {
  95.                     Cl *= 1 - shadow(shadowname, Ps, "samples", shadowsamples, "blur", shadowblur, "bias", shadowbias);
  96.             }
  97.         }
  98.        
  99.         Cl = Ct * intensity * exposure;
  100.  
  101.     }
  102.  
  103. }
  104.